package cn.blunce.mylib;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * Created by Blunce on 2015/10/26 0026.
 */
public class MyApp extends Application {

    // QQ interface Btn的标识
    public static final int BTN_FLAG_MESSAGE = 0x01;
    public static final int BTN_FLAG_CONTACTS = 0x02;
    public static final int BTN_FLAG_NEWS = 0x03;
    public static final int BTN_FLAG_SETTING = 0x04;
    // QQ interface Fragment的标识
    public static final String FRAGMENT_FLAG_MESSAGE = "消息";
    public static final String FRAGMENT_FLAG_CONTACTS = "联系人";
    public static final String FRAGMENT_FLAG_NEWS = "新闻";
    public static final String FRAGMENT_FLAG_SETTING = "设置";
    public static final String FRAGMENT_FLAG_SIMPLE = "simple";

    private static SharedPreferences mFirstRun;
    private static SharedPreferences tmpOthers;


    @Override
    public void onCreate() {
        super.onCreate();
        initSharedPreferences(getApplicationContext());
    }

    private void initSharedPreferences(Context applicationContext) {
        // TODO Auto-generated method stub

        mFirstRun = PreferenceManager
                .getDefaultSharedPreferences(applicationContext);
        tmpOthers = getSharedPreferences("test", Context.MODE_PRIVATE);
    }

    /**
     * 判读是不是第一次打开
     *
     * @return
     */
    public static boolean isFirst() {
        return mFirstRun.getBoolean("ISFIRST", true);
    }

    /**
     * 初次打开
     *
     * @param is
     */
    public static void setmFirstRun(boolean is) {
        SharedPreferences.Editor editor = mFirstRun.edit();
        editor.putBoolean("ISFIRST", is).commit();
    }

    public static void saveData(String data) {
        SharedPreferences.Editor editor = tmpOthers.edit();
        editor.putString("data", data);
        editor.commit();
    }

    public static String getData() {
        return tmpOthers.getString("data", "test");
    }
}
